package cn.house.houseai.controller.user;

import cn.house.houseai.entify.Device;
import cn.house.houseai.service.DeviceService;
import cn.house.houseai.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author 羡y
 * @date 2024/9/30
 * @Description
 */
@RestController("DeviceController")
@RequestMapping("/user/device")
@Api(tags = "C端-设备相关接口")
@Slf4j
@CrossOrigin
public class DeviceController {
        @Autowired
        private DeviceService deviceService;


    @GetMapping("/query/{user_id}")
    @ApiOperation(value = "用户查询设备")
    public ResultVo queryId(@PathVariable Integer user_id) {
        return deviceService.queryId(user_id);
    }

    @PostMapping("/insert/{user_id}")
    @ApiOperation(value = "用户添加设备")
    public ResultVo insert(@PathVariable int user_id, @RequestBody Device device){
        // 参数校验
        if (device == null) {
            return new ResultVo(101, null, "设备信息不能为空");
        }

        // 调用 service 层插入设备
        return deviceService.insertDevice(user_id, device);
    }
    @PutMapping("/update/{user_id}")
    @ApiOperation(value = "用户修改设备信息")
    public ResponseEntity<ResultVo> updateDevice(@PathVariable int user_id, @RequestBody Device device) {
        ResultVo result = deviceService.updateDevice(user_id, device);
        return ResponseEntity.ok(result);
    }

}
